import redis
import json
import threading

redis_client = redis.StrictRedis(host='192.168.4.17', port=30056, db=7, password='Wanji@300552!')

deviceId = None
def get_device_id(result_target_channel):
    global deviceId
    # try:

    print("设备id ", result_target_channel)
    pubsub = redis_client.pubsub()
    pubsub.subscribe(result_target_channel)
    # 开始监听消息
    for message in pubsub.listen():
        if message['type'] == 'message':
            receive_data = message['data'].decode('utf-8')
            print("receive_data",receive_data)
            data = json.loads(receive_data)
            data_type = data['type']
            print("commandChannel类型", data_type)
            if data_type == 0 :
                deviceId = data['deviceId']
                print("deviceId", deviceId)

